<template>
  <van-nav-bar
    title="添加收货地址"
    left-text=""
    left-arrow
    @click-left="goBack"
  />
  <van-address-edit
    :area-list="areaList"
    show-set-default
    :area-columns-placeholder="['请选择', '请选择', '请选择']"
    @save="onSave"
  />
</template>
<script setup>
import { areaList } from "@vant/area-data";
const router = useRouter();
const goBack = () => {
  router.push("/business/address/index");
};
const { cookies } = useCookies();
const LoginUser = reactive(cookies.get("LoginUser"));
const onSave = async (val) => {
  let data = {
    consignee: val.name,
    code: val.areaCode,
    address: val.addressDetail,
    mobile: val.tel,
    status: val.isDefault == true ? '1' : '0',
    busid: LoginUser.id
  };
  let result = await Api.business.addressAdd(data);
  if (result.code == 1) {
    showSuccessToast({
      message: result.msg,
      onClose: function () {
        router.push("/business/address/index");
      },
    });
  } else {
    showFailToast(result.msg);
  }
};
</script>